import { _decorator, Component, Label, Node } from 'cc';
import { EventManager } from '../manager/event';
import { GameConst } from '../config/game-param';
const { ccclass, property } = _decorator;

@ccclass('UIGame')
export class UIGame extends Component {
    @property(Label) scoreLabel: Label

    private _score: number

    public set score(v: number) {
        this._score = v
        this.scoreLabel.string = this._score.toString()
    }

    onLoad() {
        EventManager.on('add-a-point', this.onMessageReceived, this)
    }

    onMessageReceived() {
        GameConst.CURRENT_SCORE += 1
        this.score = GameConst.CURRENT_SCORE
    }

    onDestroy() {
        EventManager.off('add-a-point', this.onMessageReceived, this)
    }
}


